<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
	<meta charset="utf-8" />
		<title>出票管理</title>		
		
			<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/ext-all-debug.js"></script>
<script type="text/javascript" src="static/js/jquery-1.7.2.js" />
			<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/locale/ext-lang-zh_CN.js"></script>
			<link rel="stylesheet" href="plugins/websocketInstantMsg/ext4/resources/css/ext-all.css" />
			
			
</head>
<body>
<div id="payment"></div>
<div id="payment1"></div>
</body>
<script type="text/javascript">
Ext.onReady(function(){
	Ext.QuickTips.init();
	var store = Ext.create('Ext.data.Store', {
		fields: ["id","invoice_app_code","check_code","app_dept_name","app_person_name","app_time","settlement_dept",
		         "invoice_type","tax_rate","tax_price","non_tax_price","value_added_tax","is_cancel","is_make_red","bill_examine","is_issue"
		         ],
		pageSize: 30,  //页容量5条数据
		//是否在服务端排序 （true的话，在客户端就不能排序）
		remoteSort: false,
		remoteFilter: true,
		proxy: {
			type: 'ajax',
			url: '<%=basePath%>invoiceMgr/invoiceInfo',
			reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
				type: 'json', //返回数据类型为json格式
				root: 'result.list',  //数据
				totalProperty: 'result.total' //数据总条数
			}
		},
		sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
		autoLoad: true
	});
	var store1 = Ext.create('Ext.data.Store', {
		fields: ["id","invoice_app_code","check_code","BILL_CODE","SETTLEMENT_UNIT","app_dept_name","BUSINESS_TYPE","COST_TYPE","app_person_name","app_time","settlement_dept",
		         "invoice_type","tax_rate","tax_price","non_tax_price","value_added_tax",
		         ],
		pageSize: 30,  //页容量5条数据
		//是否在服务端排序 （true的话，在客户端就不能排序）
		remoteSort: false,
		remoteFilter: true,
		proxy: {
			type: 'ajax',
			url: '<%=basePath%>invoiceMgr/invoiceDetil',
			reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
				type: 'json', //返回数据类型为json格式
				root: 'result.list',  //数据
				totalProperty: 'result.total' //数据总条数
			}
		},
		sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
		autoLoad: true
	});
	var grid = Ext.create('Ext.grid.Panel', {
		renderTo:'payment',
		store: store,
		id:'grid',
		forceFit: true,
		height: 325,
		title:'申请待处理内容',
		stripeRows:true,
		columnLines: true,
// 		plugins:[invoice_unit_cellEditing],
		selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"single", allowDeselect: true, showHeaderCheckbox:false}),
		columns: [
			{text: 'id', dataIndex: 'id',hidden:true},
			{text: '申请单号', dataIndex: 'invoice_app_code'},
			{text: '对账单号', dataIndex: 'check_code'},
			{text: '申请部门', dataIndex: 'app_dept_name'},
			{text: '申请时间', dataIndex: 'app_time'},
			{text: '申请人', dataIndex: 'app_person_name', align: 'left'},
			{text: '结算单位', dataIndex: 'settlement_dept', align: 'left'},
			{text: '发票类型', dataIndex: 'invoice_type', align: 'left'},
			{text: '税率', dataIndex: 'tax_rate', align: 'left'},
			{text: '未含税金额', dataIndex: 'tax_price', align: 'left'},
			{text: '增值税额', dataIndex: 'value_added_tax', align: 'left'},	
			{text: '是否作废', dataIndex: 'is_cancel', align: 'left',hidden:true},	
			{text: '是否冲红', dataIndex: 'is_make_red', align: 'left',hidden:true},	
			{text: '是否否决', dataIndex: 'bill_examine', align: 'left',hidden:true},	
			{text: '是否开具', dataIndex: 'is_issue', align: 'left',hidden:true},	
		],
		bbar: [{
			xtype: 'pagingtoolbar',
			store: store,
			displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
			emptyMsg: "没有数据",
			beforePageText: "当前页",
			afterPageText: "共{0}页",
			displayInfo: true
		}],

		tbar: [{text: '开具', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/control_rewind.png',handler: function(){
			 var records = grid.getSelectionModel().getSelection();
        	 if(records.length==0){
	       			Ext.Msg.alert("提示","请选择需要开具的发票");return;
	       		}
	       		if(records.length>1){
	       			Ext.Msg.alert("提示","只能开具一张发票");return;
	       		}
	       		
	       		if(records[0].data.is_issue==1){
	       			Ext.Msg.alert("提示","已开具不能再次开具发票");return;
	       		}
	       		if(records[0].data.bill_examine==1){
	       			Ext.Msg.alert("提示","已否决不能开具发票");return;
	       		}
	       		if(records[0].data.is_cancel==1){
	       			Ext.Msg.alert("提示","已作废不能开具发票");return;
	       		}
	       		if(records[0].data.is_make_red==1){
	       			Ext.Msg.alert("提示","已冲红不能开具发票");return;
	       		}
	       		var needful = {
	       				xtype: 'fieldset',
       					title: '购买方',
       					layout: 'vbox',
       					columnWidth:1/2,
       					//collapsible: true,
       					//collapsed: false,
       					margin: 2,
       					padding:0,
	   					items: [
								{
       					        		xtype: 'textfield',
       					        		name: 'buy_name',
       					        		fieldLabel: '名称',
       					        		columnWidth:1/4,
       					        		allowBlank:false
       					        	},{
       					        		xtype: 'textfield',
       					        		name: 'buy_person_num',
       					        		fieldLabel: '纳税人识别号',
       					        		columnWidth:1/4,
       					        		allowBlank:false
       					        	},{
       					        		xtype: 'textfield',
       					        		name: 'buy_address',
       					        		fieldLabel: '地址',
       					        		columnWidth:1/4,
       					        		allowBlank:false
       					        	},
       					        	{
       					        		xtype: 'textfield',
       					        		name: 'buy_tel',
       					        		fieldLabel: '电话',
       					        		columnWidth:1/4,
       					        		allowBlank:false
       					        	},
       					        	{
       					        		xtype: 'textfield',
       					        		name: 'buy_bank',
       					        		fieldLabel: '开户行',
       					        		columnWidth:1/4,
       					        		allowBlank:false
       					        	},
       					        	{
       					        		xtype: 'textfield',
       					        		name: 'buy_num',
       					        		fieldLabel: '账号',
       					        		columnWidth:1/4,
       					        		allowBlank:false
       					        	},
	   					        ]
	       		}
	       		var needful1 = {
	       				xtype: 'fieldset',
       					title: '销售方',
       					layout: 'vbox',
       					columnWidth:1/2,
       					//collapsible: true,
       					//collapsed: false,
       					margin: 2,
       					padding:0,
	   					items: [
								{
       					        		xtype: 'textfield',
       					        		name: 'sale_name',
       					        		fieldLabel: '名称',
       					        		columnWidth:1/4,
       					        		allowBlank:false
       					        	},{
       					        		xtype: 'textfield',
       					        		name: 'sale_person_num',
       					        		fieldLabel: '纳税人识别号',
       					        		columnWidth:1/4,
       					        		allowBlank:false
       					        	},{
       					        		xtype: 'textfield',
       					        		name: 'sale_address',
       					        		fieldLabel: '地址',
       					        		columnWidth:1/4,
       					        		allowBlank:false
       					        	},
       					        	{
       					        		xtype: 'textfield',
       					        		name: 'sale_tel',
       					        		fieldLabel: '电话',
       					        		columnWidth:1/4,
       					        		allowBlank:false
       					        	},
       					        	{
       					        		xtype: 'textfield',
       					        		name: 'sale_bank',
       					        		fieldLabel: '开户行',
       					        		columnWidth:1/4,
       					        		allowBlank:false
       					        	},
       					        	{
       					        		xtype: 'textfield',
       					        		name: 'sale_num',
       					        		fieldLabel: '账号',
       					        		columnWidth:1/4,
       					        		allowBlank:false
       					        	},
	   					        ]
	       		}
	       		var win = Ext.create("Ext.window.Window", {
	 				title: "开具发票信息",
	 				modal:true,
	 				width: 600,
	 				height: 400,
	 				maximizable: true,
	 				closeAction:'destroy',
	 				layout: "fit",
//	  				margin: '3 3 0',
	 		        buttonAlign:'center',
	 				items: [
	 				        	{
	 				        		xtype: "form",
	 				        		id:'form',
	 				        		bodyPadding: 5,
	 				        		layout: "column",
	 				        		defaults: {
	 				        			border: true,
	 				        			flex: 1,
	 				        			anchor: '100%'
	 				        		},
	 				        		fieldDefaults: {
	 				        			labelWidth: 92,
	 				        			labelAlign: "right",
	 				        			//flex: 1,
	 				        			margin: 5,
	 				        			labelStyle: 'color:green;'
	 				        		},
	 				        		items: [
	 				        		         {
			   					        		xtype: 'textfield',
			   					        		name: 'invoice_app_code',
			   					        		fieldLabel: '申请号',
			   					        		columnWidth:1/2,
			   					        		readOnly:true,
			   					        		fieldStyle:'color:red',
			   					        		value:records[0].data.invoice_app_code,
			   					        		allowBlank:false
			   					        	},{
			   					        		xtype: 'textarea',
			   					        		name: 'invoice_remark',
			   					        		fieldLabel: '开票备注信息',
			   					        		columnWidth:1/2,
			   					        		allowBlank:false
			   					        	},needful,needful1,
	 				        		      
	 				        		        ]
	 				        	}
	 				        ],
	 				       buttons: [{
 		       		            text: '开具',
 		       		            handler: function(){
 		       		            	var form = Ext.getCmp('form').getForm();
 		       		               if(form.isValid()){
 		       		            	form.submit({
 		       		            		params:{
 		       		            		},
 		       		            		waitTitle : '请稍后...',  
 		       		            		waitMsg : '正在保存信息,请稍后...',  
 		       		            		url:'<%=basePath%>invoiceMgr/saveInvoiceInfo',
				          				success:function(form,action){
				          					Ext.Msg.alert("提示","保存成功");
				          					store.load();
				          					win.close();
				          				},

				          			});
 		       		                }
 		       		            }
 		       		        },{
 		       		            text: '关闭',
 		       		            handler: function(){
 		       		            	win.close();
 		       		            }
 		       		        }]
	 			});
	       		win.show();
		}},
		       {text: '打印/分发', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/control_rewind.png'},
			   {text: '作废', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/control_rewind.png',handler: function(){
				   var records = grid.getSelectionModel().getSelection();
				   if(records.length==0){
		       			Ext.Msg.alert("提示","请选择需要作废的发票");return;
		       		}
		       		if(records.length>1){
		       			Ext.Msg.alert("提示","只能作废一张发票");return;
		       		}
				   Ext.Ajax.request({
  						url:'<%=basePath%>invoiceMgr/updateInvoiceState',
  						params:{
  							invoice_app_code:records[0].data.invoice_app_code,is_cancel:1
  						},
  						timeout:5000,
  						success:function(response){
  							store.load();
  							Ext.Msg.alert("成功","作废成功!");
  						},
  						failure:function(response){
  							Ext.Msg.alert("错误","请求异常!");
  						}
  					});
			   }},
			   {text: '冲红', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/control_rewind.png',handler: function(){
				   var records = grid.getSelectionModel().getSelection();
				   if(records.length==0){
		       			Ext.Msg.alert("提示","请选择需要冲红的发票");return;
		       		}
		       		if(records.length>1){
		       			Ext.Msg.alert("提示","只能冲红一张发票");return;
		       		}
				   Ext.Ajax.request({
  						url:'<%=basePath%>invoiceMgr/updateInvoiceState',
  						params:{
  							invoice_app_code:records[0].data.invoice_app_code,is_make_red:1
  						},
  						timeout:5000,
  						success:function(response){
  							store.load();
  							Ext.Msg.alert("成功","冲红成功!");
  						},
  						failure:function(response){
  							Ext.Msg.alert("错误","请求异常!");
  						}
  					});
			   }},
			   {text: '否决', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/control_rewind.png',handler: function(){
				   var records = grid.getSelectionModel().getSelection();
				   if(records.length==0){
		       			Ext.Msg.alert("提示","请选择需要否决的发票");return;
		       		}
		       		if(records.length>1){
		       			Ext.Msg.alert("提示","只能否决一张发票");return;
		       		}
				   Ext.Ajax.request({
  						url:'<%=basePath%>invoiceMgr/updateState',
  						params:{
  							invoice_app_code:records[0].data.invoice_app_code,bill_examine:0
  						},
  						timeout:5000,
  						success:function(response){
  							store.load();
  							Ext.Msg.alert("成功","冲红成功!");
  						},
  						failure:function(response){
  							Ext.Msg.alert("错误","请求异常!");
  						}
  					});
			   }}
		],
	listeners: {
		'itemclick': function (view, record, item, index, e) {
			var store = Ext.getCmp('grid1').getStore();
			store.on('beforeload', function(store,options) {  
		            var new_params = {  
		            		check_code:record.data.check_code
		            };  

		            Ext.apply(store.proxy.extraParams,new_params);  
		        });  
		        store.load();  
		}
	},
	});
	var grid1 = Ext.create('Ext.grid.Panel', {
		renderTo:'payment1',
		store: store1,
		id:'grid1',
		forceFit: true,
		height: 325,
		title:'单票收入明细',
		stripeRows:true,
		columnLines: true,
// 		plugins:[invoice_unit_cellEditing],
		selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"single", allowDeselect: true, showHeaderCheckbox:false}),
		columns: [
			{text: 'id', dataIndex: 'id',hidden:true},
			{text: '申请单号', dataIndex: 'invoice_app_code'},
			{text: '对账单号', dataIndex: 'check_code'},
			{text: '业务编号', dataIndex: 'BILL_CODE'},
			{text: '结算单位', dataIndex: 'SETTLEMENT_UNIT'},
			{text: '申请部门', dataIndex: 'app_dept_name'},
			{text: '业务类型', dataIndex: 'BUSINESS_TYPE', align: 'left'},
			{text: '发票类型', dataIndex: 'invoice_type', align: 'left'},
			{text: '发票名目', dataIndex: 'CURRENCY', align: 'left'},
			{text: '发票号', dataIndex: 'COST_TYPE', align: 'left'},
			{text: '税率', dataIndex: 'tax_rate', align: 'left'},
			{text: '未含税金额', dataIndex: 'non_tax_price', align: 'left'},	
			{text: '增值税额', dataIndex: 'value_added_tax', align: 'left'},
			{text: '开票备注信息', dataIndex: 'CURRENCY', align: 'left'},
			{text: '申请时间', dataIndex: 'app_time', align: 'left'},
			{text: '审核时间', dataIndex: 'handle_time', align: 'left'},
			{text: '开票时间', dataIndex: 'CURRENCY', align: 'left'},
			{text: '目前状态', dataIndex: 'CURRENCY', align: 'left'},
			{text: '申请人', dataIndex: 'app_person_name', align: 'left'},
		],
		bbar: [{
			xtype: 'pagingtoolbar',
			store: store1,
			displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
			emptyMsg: "没有数据",
			beforePageText: "当前页",
			afterPageText: "共{0}页",
			displayInfo: true
		}],

		tbar: []
	});
// 	  var selForm = Ext.create('Ext.form.Panel', {
// 			title:'出票管理',
// 			name: 'selForm',
// 			renderTo:'invoice',
// 			width:'100%',
// //			collapsed :true,
// 			height:'96%',
// //			collapsible:true,
// // 			bodyStyle: {
// // 				padding: '5px',
// // 				border: 1
// // 			},
// 			fieldDefaults: {
// 				labelAlign: 'left'
// 			},
// 			items: [grid,grid1]
// 		});
});

</script>
</html>